﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Mapping;

namespace NHibernate.Audit.Cfg
{
    public class DefaultAuditClassConvention : AbstractAuditClassConvention 
    {

        private string GetEntityName(PersistentClass clazz)
        {
            var realName = clazz.EntityName;
            if (string.IsNullOrEmpty(realName))
                realName = clazz.ClassName;
            return realName;
        }


        public override bool AuditClass(PersistentClass clazz)
        {
            return AuditClass(GetEntityName(clazz));
        }

        public override bool AuditClass(string entityName)
        {
            return !entityName.EndsWith("_Audit")
                && !entityName.EndsWith("RevisionInfo");
        }

        public override bool AuditProperty(Property Property)
        {
            return true;
        }

        public override bool AuditProperty(string propertyName)
        {
            return true;
        }

        public override string GetAuditClassNameFor(PersistentClass clazz)
        {
            return clazz.ClassName;
        }

        public override string GetAuditEntityNameFor(PersistentClass clazz)
        {
            return GetAuditEntityNameFor(GetEntityName(clazz));
        }

        public override string GetAuditEntityNameFor(string entityName)
        {
            return string.Format("{0}_Audit", entityName);
        }

    }
}
